package com.example.shirodemo2.shiro.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * 通用响应对象
 *
 * @author SPL
 * @since 2020-02-04 11:52
 */
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class AjaxResult {

    /**
     * 响应编号
     */
    private int code;
    /**
     * 响应信息
     */
    private String message;

    /**
     * 响应数据
     */
    private Object result;

    public AjaxResult(int code) {
        this.code = code;
    }

    public AjaxResult(int code, String msg) {
        this.code = code;
        this.message = msg;
    }


    public static AjaxResult error(int code, String msg) {
        return new AjaxResult().setCode(code).setMessage(msg);
    }

    public static AjaxResult success() {
        return new AjaxResult().setCode(200).setMessage("成功");
    }

    public static AjaxResult success(Object o) {
        return new AjaxResult().setCode(200).setMessage("成功").setResult(o);
    }

}
